namespace QMVnSoft.Opening
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCDSLDDEditor : FormOpenningEditor
    {
        private IContainer components;
        private LabelControl lblMa_Sp;
        private LabelControl lblSo_Luong;
        private LabelControl lblTy_Le_Ht;
        private TextSearch txtMa_Sp;
        private TextNumeric txtSo_Luong;
        private TextControl txtTen_Sp;
        private TextNumeric txtTy_Le_Ht;

        public FormCDSLDDEditor()
        {
            this.InitializeComponent();
        }

        public FormCDSLDDEditor(object poUserDefined1, object poUserDefined2, object poUserDefined3) : base(poUserDefined1, poUserDefined2, poUserDefined3)
        {
            this.InitializeComponent();
            if (((int) base.UserDefined3) == 0)
            {
                this.lblTy_Le_Ht.Visible = false;
                this.txtTy_Le_Ht.Visible = false;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCDSLDDEditor));
            this.txtTen_Sp = new QMVnSoft.Controls.TextControl();
            this.txtMa_Sp = new QMVnSoft.Controls.TextSearch();
            this.lblMa_Sp = new QMVnSoft.Controls.LabelControl();
            this.lblTy_Le_Ht = new QMVnSoft.Controls.LabelControl();
            this.txtTy_Le_Ht = new QMVnSoft.Controls.TextNumeric();
            this.txtSo_Luong = new QMVnSoft.Controls.TextNumeric();
            this.lblSo_Luong = new QMVnSoft.Controls.LabelControl();
            this.SuspendLayout();
            // 
            // txtTen_Sp
            // 
            this.txtTen_Sp.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Sp.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Sp.CheckTextSearched = false;
            this.txtTen_Sp.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Sp.Enabled = false;
            this.txtTen_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Sp.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Sp.Location = new System.Drawing.Point(243, 31);
            this.txtTen_Sp.Name = "txtTen_Sp";
            this.txtTen_Sp.OldValue = null;
            this.txtTen_Sp.Size = new System.Drawing.Size(240, 13);
            this.txtTen_Sp.TabIndex = 80;
            this.txtTen_Sp.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Sp.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Sp.Value = ((object)(resources.GetObject("txtTen_Sp.Value")));
            // 
            // txtMa_Sp
            // 
            this.txtMa_Sp.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Sp.CheckTextSearched = false;
            this.txtMa_Sp.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Sp.FieldDisplay = "Ten_Sp";
            this.txtMa_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Sp.Location = new System.Drawing.Point(126, 28);
            this.txtMa_Sp.MaxLength = 32;
            this.txtMa_Sp.Name = "txtMa_Sp";
            this.txtMa_Sp.OldValue = null;
            this.txtMa_Sp.Size = new System.Drawing.Size(111, 20);
            this.txtMa_Sp.TabIndex = 3;
            this.txtMa_Sp.TableName = "DMSP";
            this.txtMa_Sp.TextDisplay = this.txtTen_Sp;
            this.txtMa_Sp.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Sp.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Sp.Value = ((object)(resources.GetObject("txtMa_Sp.Value")));
            // 
            // lblMa_Sp
            // 
            this.lblMa_Sp.AutoSize = true;
            this.lblMa_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Sp.Location = new System.Drawing.Point(12, 31);
            this.lblMa_Sp.Name = "lblMa_Sp";
            this.lblMa_Sp.Size = new System.Drawing.Size(55, 14);
            this.lblMa_Sp.TabIndex = 78;
            this.lblMa_Sp.Text = "Sản phẩm";
            // 
            // lblTy_Le_Ht
            // 
            this.lblTy_Le_Ht.AutoSize = true;
            this.lblTy_Le_Ht.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTy_Le_Ht.Location = new System.Drawing.Point(12, 73);
            this.lblTy_Le_Ht.Name = "lblTy_Le_Ht";
            this.lblTy_Le_Ht.Size = new System.Drawing.Size(108, 14);
            this.lblTy_Le_Ht.TabIndex = 86;
            this.lblTy_Le_Ht.Text = "Tỷ lệ hoàn thành (%)";
            // 
            // txtTy_Le_Ht
            // 
            this.txtTy_Le_Ht.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTy_Le_Ht.Location = new System.Drawing.Point(126, 70);
            this.txtTy_Le_Ht.Name = "txtTy_Le_Ht";
            this.txtTy_Le_Ht.NumericValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.txtTy_Le_Ht.OldValue = null;
            this.txtTy_Le_Ht.Size = new System.Drawing.Size(129, 20);
            this.txtTy_Le_Ht.TabIndex = 5;
            this.txtTy_Le_Ht.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtTy_Le_Ht.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.Percent;
            this.txtTy_Le_Ht.Value = ((object)(resources.GetObject("txtTy_Le_Ht.Value")));
            // 
            // txtSo_Luong
            // 
            this.txtSo_Luong.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSo_Luong.Location = new System.Drawing.Point(126, 49);
            this.txtSo_Luong.Name = "txtSo_Luong";
            this.txtSo_Luong.NumericValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.txtSo_Luong.OldValue = null;
            this.txtSo_Luong.Size = new System.Drawing.Size(129, 20);
            this.txtSo_Luong.TabIndex = 4;
            this.txtSo_Luong.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtSo_Luong.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.Quantity;
            this.txtSo_Luong.Value = ((object)(resources.GetObject("txtSo_Luong.Value")));
            // 
            // lblSo_Luong
            // 
            this.lblSo_Luong.AutoSize = true;
            this.lblSo_Luong.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblSo_Luong.Location = new System.Drawing.Point(12, 52);
            this.lblSo_Luong.Name = "lblSo_Luong";
            this.lblSo_Luong.Size = new System.Drawing.Size(51, 14);
            this.lblSo_Luong.TabIndex = 86;
            this.lblSo_Luong.Text = "Số lượng";
            // 
            // FormCDSLDDEditor
            // 
            this.AddTitleText = "Thêm số lượng sản phẩm dở dang";
            this.ClientSize = new System.Drawing.Size(495, 158);
            this.Controls.Add(this.txtMa_Sp);
            this.Controls.Add(this.lblSo_Luong);
            this.Controls.Add(this.lblTy_Le_Ht);
            this.Controls.Add(this.txtSo_Luong);
            this.Controls.Add(this.txtTy_Le_Ht);
            this.Controls.Add(this.txtTen_Sp);
            this.Controls.Add(this.lblMa_Sp);
            this.EditTitleText = "Sửa số lượng sản phẩm dở dang";
            this.Name = "FormCDSLDDEditor";
            this.Text = "Thêm số lượng sản phẩm dở dang";
            this.Controls.SetChildIndex(this.lblMa_Sp, 0);
            this.Controls.SetChildIndex(this.txtTen_Sp, 0);
            this.Controls.SetChildIndex(this.txtTy_Le_Ht, 0);
            this.Controls.SetChildIndex(this.txtSo_Luong, 0);
            this.Controls.SetChildIndex(this.lblTy_Le_Ht, 0);
            this.Controls.SetChildIndex(this.lblSo_Luong, 0);
            this.Controls.SetChildIndex(this.txtMa_Sp, 0);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void OnReset()
        {
            if (base.NewChecked)
            {
                this.txtSo_Luong.Value = 0;
                this.txtTy_Le_Ht.Value = 0;
            }
        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if ((((DateTime) base.UserDefined2) < AppInstance.OpeningDateOfSubEnterprice) || (((DateTime) base.UserDefined2) <= AppInstance.EndingDateOfSubEnterprice))
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (this.txtSo_Luong.NumericValue == 0M)
            {
                MessageBox.Show("Chưa nhập số lượng sản phẩm dở dang!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
                localCurrentRow["Ma_Dvcs"] = AppInstance.Subsidiary;
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Ma_Sp"] = this.txtMa_Sp.Value;
            localCurrentRow["Ten_Sp"] = this.txtTen_Sp.Value;
            localCurrentRow["Dvt"] = this.txtMa_Sp.GetFieldData("Dvt");
            localCurrentRow["So_Luong"] = this.txtSo_Luong.Value;
            localCurrentRow["Ty_Le_Ht"] = this.txtTy_Le_Ht.Value;
            localCurrentRow["Ngay_Ct"] = base.UserDefined2;
            CDSLDDDataAccess access = new CDSLDDDataAccess();
            if (access.Save(base.NewChecked, localCurrentRow) == -1)
            {
                MessageBox.Show("Sản phẩm đã được ghi nhận!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            base.SavedMasterOrder = localCurrentRow["Stt"];
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtMa_Sp.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtMa_Sp.Value = base.LocalCurrentRow["Ma_Sp"];
            this.txtTen_Sp.Value = base.LocalCurrentRow["Ten_Sp"];
            this.txtSo_Luong.Value = base.LocalCurrentRow["So_Luong"];
            this.txtTy_Le_Ht.Value = base.LocalCurrentRow["Ty_Le_Ht"];
        }
    }
}

